use std::sync::Arc;

use sqlx::PgPool;

use crate::{AppState, Error, Result};

pub fn new_id() -> String {
    xid::new().to_string()
}

pub fn get_pool(state: &AppState) -> Arc<PgPool> {
    state.pool.clone()
}

pub fn hash_pwd(pwd: &str) -> Result<String> {
    bcrypt::hash(pwd, bcrypt::DEFAULT_COST).map_err(Error::from)
}

pub fn verify_pwd(pwd: &str, hashed_pwd: &str) -> Result<bool> {
    bcrypt::verify(pwd, hashed_pwd).map_err(Error::from)
}
